/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui.panels;

import model.Laminaat;


/**
 *
 * @author Memet
 */
public class LaminatePanel extends javax.swing.JPanel {

    /**
     * Creates new form LaminatePanel
     */
    public LaminatePanel() {
        initComponents();
        updateForm();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        lstLaminates = new javax.swing.JList();

        jScrollPane1.setFont(new java.awt.Font("Trebuchet MS", 0, 14)); // NOI18N

        lstLaminates.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        lstLaminates.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lstLaminatesMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(lstLaminates);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void lstLaminatesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lstLaminatesMouseClicked
        if (lstLaminates.getSelectedIndex() != -1) {
            LaminateOperationPanel operations = new LaminateOperationPanel();
            operations.setLaminate((Laminaat) lstLaminates.getSelectedValue());
            /* todo refactor
            Global.menu.setOperations(operations);*/
        }
    }//GEN-LAST:event_lstLaminatesMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JList lstLaminates;
    // End of variables declaration//GEN-END:variables

    public void updateForm() {
        int index = lstLaminates.getSelectedIndex();
        /* todo refactor
        Laminaat[] data = new Laminaat[Global.data.getLaminatesCount()];
        int teller = 0;
        Iterator<Laminaat> it = Global.data.getLaminates();
        while(it.hasNext())
        {
          Laminaat t = it.next();
          data[teller] = t;
          teller++;
        }
        JList hold = new JList(data);
        lstLaminates.setModel(hold.getModel());
        lstLaminates.setSelectedIndex(index);
        lstLaminates.validate();
        this.repaint();
        this.revalidate();*/
    }
    
    void clearSelection() {
        lstLaminates.clearSelection();
    }
}
